#!/bin/sh
#
# $Id: postinstall,v 1.7 2009-07-28 18:33:02 ghantoos Exp $
#
# RPM build postinstall script

# Check if rpm is being _installed_ (as opposed to _upgraded_)
# if installation process, then proceed
# source: http://www.ibm.com/developerworks/library/l-rpm3.html
# case of installation
if [ "$1" = "1" ] ; then

    if ! getent group lshell 2>&1 > /dev/null; then
        addgroup --system lshell
    fi

    chown root:lshell /var/log/lshell/
    chmod 770 /var/log/lshell/

    #####
    # This part is taken from debian add-shell(8) script
    #####

    lshell=/usr/bin/lshell
    file=/etc/shells
    tmpfile=${file}.tmp

    set -o noclobber

    trap "rm -f ${tmpfile}" EXIT

    if ! cat ${file} > ${tmpfile}
    then
            cat 1>&2 <<EOF
    Either another instance of $0 is running, or it was previously interrupted.
    Please examine ${tmpfile} to see if it should be moved onto ${file}.
EOF
            exit 1
    fi


    if ! grep -q "^${lshell}" ${tmpfile}
    then
        echo ${lshell} >> ${tmpfile}
    fi
    chmod --reference=${file} ${tmpfile}
    chown --reference=${file} ${tmpfile}

    mv ${tmpfile} ${file}

    trap "" EXIT
    exit 0

# case of upgrade
else
    chown root:lshell /var/log/lshell/
    chmod -R 770 /var/log/lshell/

    mv /etc/lshell.conf /etc/lshell.conf-rpm
    mv /etc/lshell.conf-preinstall /etc/lshell.conf
    exit 0

fi

